<!-- src/views/companyInfo.vue -->
<template>
    <div class="company-info-container">

        <!-- 搜索栏 -->
        <div class="search-bar">
            <van-search v-model="searchValue" placeholder="请输入企业名称" @search="onSearch" />
        </div>
        <!-- 加载状态 -->
        <van-loading v-if="loading" size="35px" vertical>加载中...</van-loading>
        <!-- 企业信息卡片 -->
        <div class="cards-container" v-if="!loading">
            <CompanyCard v-for="company in filteredCompanies" :key="company.id" :company="company"
                @view-details="handleViewDetails" class="card-item" />
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import CompanyCard from '../components/companyCardComponents/companyCard.vue'
import { getAllEnterprise } from '../api/enterprise'

// 搜索值
const searchValue = ref('')

// 加载状态
const loading = ref(true)

// 企业数据
const companies = ref([
    {
        "id": 872111162,
        "fullName": "测试企业1",
        "totalCount": 100,
        "hightCount": 10,
        "midCount": 10,
        "baseCount": 10,
        "frontCount": 70,
        "business": "测试业务",
        "lastRevenue": "10000",
        "version": 0,
        "createAt": "2025-10-28T17:11:30",
        "updateAt": "2025-10-31T14:21:46",
        "orgJson": "[{\"id\":1761731418098,\"name\":\"测试1\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"无上级部门/顶级部门\",\"staffCount\":\"100\",\"childrenNodes\":[{\"id\":1761792977993,\"name\":\"测试2\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试1\",\"staffCount\":\"123\",\"childrenNodes\":[{\"id\":1761792992272,\"name\":\"测试3\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试2\",\"staffCount\":\"123\",\"childrenNodes\":[]},{\"id\":1761793080357,\"name\":\"测试5\",\"manager\":\"131123\",\"gender\":\"男\",\"parentNode\":\"测试2\",\"staffCount\":\"123\",\"childrenNodes\":[]}]},{\"id\":1761793017962,\"name\":\"测试4\",\"manager\":\"测试4\",\"gender\":\"男\",\"parentNode\":\"测试1\",\"staffCount\":\"123\",\"childrenNodes\":[]}]},{\"id\":1761793108821,\"name\":\"测试6\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"无上级部门/顶级部门\",\"staffCount\":\"100\",\"childrenNodes\":[{\"id\":1761793124764,\"name\":\"测试7\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试6\",\"staffCount\":\"1001\",\"childrenNodes\":[{\"id\":1761793910378,\"name\":\"测试9\",\"manager\":\"测试9\",\"gender\":\"男\",\"parentNode\":\"测试7\",\"staffCount\":\"100\",\"childrenNodes\":[]}]},{\"id\":1761793151415,\"name\":\"测试8\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试6\",\"staffCount\":\"123\",\"childrenNodes\":[{\"id\":1761793931373,\"name\":\"测试10\",\"manager\":\"测试10\",\"gender\":\"男\",\"parentNode\":\"测试8\",\"staffCount\":\"100\",\"childrenNodes\":[]}]}]}]",
        "currentMenber": "[{\"department\":\"测试1\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"高层\",\"performance\":\"优秀\"},{\"department\":\"测试1/测试4\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"一线\",\"performance\":\"优秀\"},{\"department\":\"测试1/测试4\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"高层\",\"performance\":\"优秀\"}]"
    },
    {
        "id": 899219312,
        "fullName": "测试企业2",
        "totalCount": 170,
        "hightCount": 10,
        "midCount": 20,
        "baseCount": 30,
        "frontCount": 110,
        "business": "测试业务",
        "lastRevenue": "10000",
        "version": 0,
        "createAt": "2025-10-28T17:10:48",
        "updateAt": "2025-10-31T14:21:46",
        "orgJson": "[{\"id\":1761731418098,\"name\":\"测试1\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"无上级部门/顶级部门\",\"staffCount\":\"100\",\"childrenNodes\":[{\"id\":1761792977993,\"name\":\"测试2\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试1\",\"staffCount\":\"123\",\"childrenNodes\":[{\"id\":1761792992272,\"name\":\"测试3\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试2\",\"staffCount\":\"123\",\"childrenNodes\":[]},{\"id\":1761793080357,\"name\":\"测试5\",\"manager\":\"131123\",\"gender\":\"男\",\"parentNode\":\"测试2\",\"staffCount\":\"123\",\"childrenNodes\":[]}]},{\"id\":1761793017962,\"name\":\"测试4\",\"manager\":\"测试4\",\"gender\":\"男\",\"parentNode\":\"测试1\",\"staffCount\":\"123\",\"childrenNodes\":[]}]},{\"id\":1761793108821,\"name\":\"测试6\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"无上级部门/顶级部门\",\"staffCount\":\"100\",\"childrenNodes\":[{\"id\":1761793124764,\"name\":\"测试7\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试6\",\"staffCount\":\"1001\",\"childrenNodes\":[{\"id\":1761793910378,\"name\":\"测试9\",\"manager\":\"测试9\",\"gender\":\"男\",\"parentNode\":\"测试7\",\"staffCount\":\"100\",\"childrenNodes\":[]}]},{\"id\":1761793151415,\"name\":\"测试8\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试6\",\"staffCount\":\"123\",\"childrenNodes\":[{\"id\":1761793931373,\"name\":\"测试10\",\"manager\":\"测试10\",\"gender\":\"男\",\"parentNode\":\"测试8\",\"staffCount\":\"100\",\"childrenNodes\":[]}]}]}]",
        "currentMenber": "[{\"department\":\"测试1\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"高层\",\"performance\":\"优秀\"},{\"department\":\"测试1/测试4\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"一线\",\"performance\":\"优秀\"},{\"department\":\"测试1/测试4\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"高层\",\"performance\":\"优秀\"}]"
    }
    ,
    {
        "id": 899219312,
        "fullName": "测试企业2",
        "totalCount": 170,
        "hightCount": 10,
        "midCount": 20,
        "baseCount": 30,
        "frontCount": 110,
        "business": "测试业务",
        "lastRevenue": "10000",
        "version": 0,
        "createAt": "2025-10-28T17:10:48",
        "updateAt": "2025-10-31T14:21:46",
        "orgJson": "[{\"id\":1761731418098,\"name\":\"测试1\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"无上级部门/顶级部门\",\"staffCount\":\"100\",\"childrenNodes\":[{\"id\":1761792977993,\"name\":\"测试2\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试1\",\"staffCount\":\"123\",\"childrenNodes\":[{\"id\":1761792992272,\"name\":\"测试3\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试2\",\"staffCount\":\"123\",\"childrenNodes\":[]},{\"id\":1761793080357,\"name\":\"测试5\",\"manager\":\"131123\",\"gender\":\"男\",\"parentNode\":\"测试2\",\"staffCount\":\"123\",\"childrenNodes\":[]}]},{\"id\":1761793017962,\"name\":\"测试4\",\"manager\":\"测试4\",\"gender\":\"男\",\"parentNode\":\"测试1\",\"staffCount\":\"123\",\"childrenNodes\":[]}]},{\"id\":1761793108821,\"name\":\"测试6\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"无上级部门/顶级部门\",\"staffCount\":\"100\",\"childrenNodes\":[{\"id\":1761793124764,\"name\":\"测试7\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试6\",\"staffCount\":\"1001\",\"childrenNodes\":[{\"id\":1761793910378,\"name\":\"测试9\",\"manager\":\"测试9\",\"gender\":\"男\",\"parentNode\":\"测试7\",\"staffCount\":\"100\",\"childrenNodes\":[]}]},{\"id\":1761793151415,\"name\":\"测试8\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试6\",\"staffCount\":\"123\",\"childrenNodes\":[{\"id\":1761793931373,\"name\":\"测试10\",\"manager\":\"测试10\",\"gender\":\"男\",\"parentNode\":\"测试8\",\"staffCount\":\"100\",\"childrenNodes\":[]}]}]}]",
        "currentMenber": "[{\"department\":\"测试1\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"高层\",\"performance\":\"优秀\"},{\"department\":\"测试1/测试4\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"一线\",\"performance\":\"优秀\"},{\"department\":\"测试1/测试4\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"高层\",\"performance\":\"优秀\"}]"
    }
    ,
    {
        "id": 899219312,
        "fullName": "测试企业2",
        "totalCount": 170,
        "hightCount": 10,
        "midCount": 20,
        "baseCount": 30,
        "frontCount": 110,
        "business": "测试业务",
        "lastRevenue": "10000",
        "version": 0,
        "createAt": "2025-10-28T17:10:48",
        "updateAt": "2025-10-31T14:21:46",
        "orgJson": "[{\"id\":1761731418098,\"name\":\"测试1\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"无上级部门/顶级部门\",\"staffCount\":\"100\",\"childrenNodes\":[{\"id\":1761792977993,\"name\":\"测试2\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试1\",\"staffCount\":\"123\",\"childrenNodes\":[{\"id\":1761792992272,\"name\":\"测试3\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试2\",\"staffCount\":\"123\",\"childrenNodes\":[]},{\"id\":1761793080357,\"name\":\"测试5\",\"manager\":\"131123\",\"gender\":\"男\",\"parentNode\":\"测试2\",\"staffCount\":\"123\",\"childrenNodes\":[]}]},{\"id\":1761793017962,\"name\":\"测试4\",\"manager\":\"测试4\",\"gender\":\"男\",\"parentNode\":\"测试1\",\"staffCount\":\"123\",\"childrenNodes\":[]}]},{\"id\":1761793108821,\"name\":\"测试6\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"无上级部门/顶级部门\",\"staffCount\":\"100\",\"childrenNodes\":[{\"id\":1761793124764,\"name\":\"测试7\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试6\",\"staffCount\":\"1001\",\"childrenNodes\":[{\"id\":1761793910378,\"name\":\"测试9\",\"manager\":\"测试9\",\"gender\":\"男\",\"parentNode\":\"测试7\",\"staffCount\":\"100\",\"childrenNodes\":[]}]},{\"id\":1761793151415,\"name\":\"测试8\",\"manager\":\"12213\",\"gender\":\"男\",\"parentNode\":\"测试6\",\"staffCount\":\"123\",\"childrenNodes\":[{\"id\":1761793931373,\"name\":\"测试10\",\"manager\":\"测试10\",\"gender\":\"男\",\"parentNode\":\"测试8\",\"staffCount\":\"100\",\"childrenNodes\":[]}]}]}]",
        "currentMenber": "[{\"department\":\"测试1\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"高层\",\"performance\":\"优秀\"},{\"department\":\"测试1/测试4\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"一线\",\"performance\":\"优秀\"},{\"department\":\"测试1/测试4\",\"name\":\"测试\",\"position\":\"测试\",\"level\":\"高层\",\"performance\":\"优秀\"}]"
    }
])

// 过滤后的企业数据
const filteredCompanies = computed(() => {
    if (!searchValue.value) return companies.value
    return companies.value.filter(company =>
        company.fullName.includes(searchValue.value)
    )
})

// 搜索处理函数
const onSearch = () => {
    console.log('搜索:', searchValue.value)
}

// 处理查看详情事件
const handleViewDetails = (id: number) => {
    console.log('查看企业详情:', id)
    // 在这里添加跳转到详情页的逻辑
}

//获取所有企业信息
const getAllCompanies = async () => {
    const response: any = await getAllEnterprise().catch(err => {
        console.log("获取失败", err);
    });
    console.log("获取的响应数据", response);
    companies.value = response.data
    loading.value = false
}


//挂载时获取所有企业信息
onMounted(async () => {
    await getAllCompanies()
})
</script>

<style scoped>
.company-info-container {
    width: 95vw;
    padding: 10px;
}

.search-bar {
    margin-bottom: 15px;
}


.cards-container {
    margin-bottom: 5px;
}

.cards-container {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: 80vh;
    /* 根据需要调整高度 */
    padding: 5px;
    scrollbar-width: none;
    /* 隐藏滚动条（Firefox） */
}

.cards-container::-webkit-scrollbar {
    display: none;
    /* 隐藏滚动条（Chrome/Safari） */
}

.card-item {
    flex-shrink: 0;
}
</style>